﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;

namespace CommunitySystem.Model.Silverlight
{
    public class DataEntity : INotifyPropertyChanged
    {
        private bool _IsValidate = true;

        public bool IsValidate
        {
            get { return _IsValidate; }
            set { _IsValidate = value; }
        }

        public virtual void Validate(string PropName, object value, object instance)
        {
            if (IsValidate)
                Validator.ValidateProperty(value, new ValidationContext(instance, null, null) { MemberName = PropName });
            OnPropertyChanged(PropName);
        }

        public event PropertyChangedEventHandler PropertyChanged;

        public void OnPropertyChanged(string propName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propName));
            }
        }
        
    }
}
